* Set current directory and open log
cd "E:\Seagate Sync\VOL\Personal folder\Documents\Research\Current projects\Working party meetings\Posted\EUP 160404"
capture log close
log using "Data management\wpar-management04-workingparties01-clean", replace text


*******************************************************************************
* Partial identification of working parties and standardization of their titles
*******************************************************************************


* Project and author information
********************************
* Programme:	wpar-management04-workingparties01-clean.do
* Date:			4 April 2016
* Author:		Frank Haege, University of Limerick
* Contact:		frank.haege@ul.ie 

* Do-file description
*********************
* Relying on the annual meeting calendars supplied by the Council Secretariat in response
* to a request for access to information, this and the following do-files generate a dataset with information 
* on the dates and duration (in half-days) of working party meetings between 1995 and 2014.
* This do-file partially standardizes the format of working party titles to make the coding more
* efficient. Meetings within the Council by bodies other than working parties are identified and coded
* accordingly.


* Clear memory  
**************
version 12.0
clear all
macro drop _all
set more off

* Load dataset
use "Input data\wpar-rawdata-workingparties-1995-2014.dta", clear
describe, d

* Label working party name variable
label var wpname "Working party name"

* Generate date of meeting variable
generate date2 = date(date, "DMY")
format date2 %d
drop date
rename date2 date
label var date "Meeting date"
codebook date, m

* Generate categorical time-slot variable
generate slot = .
replace slot = 1 if slots == "AM"
replace slot = 2 if slots == "PM"
replace slot = 3 if slots == "EV"
replace slot = 4 if slots == "AM-PM"
replace slot = 5 if slots == "PM-EV"
replace slot = 6 if slots == "AM-EV"
replace slot = 7 if slots == "AM-PM-EV"
label var slot "Meeting time slot"
label def slotl 1 "AM" 2 "PM" 3 "EV" 4 "AM-PM" 5 "PM-EV" 6 "AM-EV" 7 "AM-PM-EV"
label val slot slotl
tab slots, m
tab slot, m
drop slots

* Generate year variable
generate year = year(date)
label var year "Meeting year"
tab year

* Generate month variable
generate month = month(date)
label var month "Meeting month"
label def monthl 1 "January" 2 "February" 3 "March" 4 "April" 5 "May" 6 "June" /*
	*/ 7 "July" 8 "August" 9 "September" 10 "October" 11 "November" 12 "December"
label val month monthl
sort year
by year: tab month

* Generate week of year variable
generate week = week(date)
label var week "Meeting week"
tab week, m

* Generate day of week variable
generate day = dow(date)
label var day "Meeting day of week"
label define dayl 0 "Sunday" 1 "Monday" 2 "Tuesday" 3 "Wednesday" /*
	*/ 4 "Thursday" 5 "Friday" 6 "Saturday"
label val day dayl
tab day, m

* Generate semester variable
generate semester = halfyear(date)
label var semester "Meeting semester"
label def semesterl 1 "First semester" 2 "Second semester"
label val semester semesterl
tab semester, m

* Generate presidency variable
generate pres = .
replace pres = 1 if year == 1995 & month <= 6
replace pres = 2 if year == 1995 & month > 6
replace pres = 3 if year == 1996 & month <= 6
replace pres = 4 if year == 1996 & month > 6
replace pres = 5 if year == 1997 & month <= 6
replace pres = 6 if year == 1997 & month > 6
replace pres = 7 if year == 1998 & month <= 6
replace pres = 8 if year == 1998 & month > 6
replace pres = 9 if year == 1999 & month <= 6
replace pres = 10 if year == 1999 & month > 6
replace pres = 11 if year == 2000 & month <= 6
replace pres = 12 if year == 2000 & month > 6
replace pres = 13 if year == 2001 & month <= 6
replace pres = 14 if year == 2001 & month > 6
replace pres = 15 if year == 2002 & month <= 6
replace pres = 16 if year == 2002 & month > 6
replace pres = 17 if year == 2003 & month <= 6
replace pres = 18 if year == 2003 & month > 6
replace pres = 19 if year == 2004 & month <= 6
replace pres = 20 if year == 2004 & month > 6
replace pres = 21 if year == 2005 & month <= 6
replace pres = 22 if year == 2005 & month > 6
replace pres = 23 if year == 2006 & month <= 6
replace pres = 24 if year == 2006 & month > 6
replace pres = 25 if year == 2007 & month <= 6
replace pres = 26 if year == 2007 & month > 6
replace pres = 27 if year == 2008 & month <= 6
replace pres = 28 if year == 2008 & month > 6
replace pres = 29 if year == 2009 & month <= 6
replace pres = 30 if year == 2009 & month > 6
replace pres = 31 if year == 2010 & month <= 6
replace pres = 32 if year == 2010 & month > 6
replace pres = 33 if year == 2011 & month <= 6
replace pres = 34 if year == 2011 & month > 6
replace pres = 35 if year == 2012 & month <= 6
replace pres = 36 if year == 2012 & month > 6
replace pres = 37 if year == 2013 & month <= 6
replace pres = 38 if year == 2013 & month > 6
replace pres = 39 if year == 2014 & month <= 6
replace pres = 40 if year == 2014 & month > 6
label var pres "Presidency"

* Define labels for presidency variable
label def presl /*
	*/ 1 "FR-1-95" /*
	*/ 2 "ES-2-95" /*
	*/ 3 "IT-1-96" /*
	*/ 4 "IE-2-96" /*
	*/ 5 "NL-1-97" /*
	*/ 6 "LU-2-97" /*
	*/ 7 "UK-1-98" /*
	*/ 8 "AT-2-98" /*
	*/ 9 "DE-1-99" /*
	*/ 10 "FI-2-99" /*
	*/ 11 "PT-1-00" /*
	*/ 12 "FR-2-00" /*
	*/ 13 "SE-1-01" /*
	*/ 14 "BE-2-01" /*
	*/ 15 "ES-1-02" /*
	*/ 16 "DK-2-02" /*
	*/ 17 "EL-1-03" /*
	*/ 18 "IT-2-03" /*
	*/ 19 "IE-1-04" /*
	*/ 20 "NL-2-04" /*
	*/ 21 "LU-1-05" /*
	*/ 22 "UK-2-05" /*
	*/ 23 "AT-1-06" /*
	*/ 24 "FI-2-06" /*
	*/ 25 "DE-1-07" /*
	*/ 26 "PT-2-07" /*	
	*/ 27 "SI-1-08" /*
	*/ 28 "FR-2-08" /*
	*/ 29 "CZ-1-09" /*
	*/ 30 "SE-2-09" /*
	*/ 31 "ES-1-10" /*
	*/ 32 "BE-2-10" /*
	*/ 33 "HU-1-11" /*
	*/ 34 "PL-2-11" /*
	*/ 35 "DK-1-12" /*
	*/ 36 "CY-2-12" /*
	*/ 37 "IE-1-13" /*
	*/ 38 "LT-2-13" /*
	*/ 39 "EL-1-14" /*
	*/ 40 "IT-2-14", modify	
label val pres presl
tab pres, m

* Sort and order data
sort date
order date slot year semester month week day pres

* Generate variable holding original string of working party title
generate wpname_orig = wpname
label var wpname_orig "Working party name (original)"

* Generate working party code variable
generate wpcode = ""
label var wpcode "Working party code"

* Generate second working party code variable for joint meetings
generate wpcode2 = ""
label var wpcode2 "Working party code 2"

* Generate third working party code variable for joint meetings
generate wpcode3 = ""
label var wpcode3 "Working party code 3"

* Drop non-sensical information
replace wpcode = "Z00" if wpname == ""
replace wpcode = "Z00" if wpname == " (suite)"
replace wpcode = "Z00" if wpname == "#NAME?"
replace wpcode = "Z00" if wpname == "RESERVEE"
replace wpcode = "Z00" if wpname == "RESERVE"
replace wpcode = "Z00" if wpname == "salle 70.4: RESERVEE"
replace wpcode = "Z00" if wpname == "70.4: RESERVEE"
replace wpcode = "Z00" if wpname == "70.4 RESERVEE"
replace wpcode = "Z00" if wpname == " ./."
replace wpcode = "Z00" if wpname == "./. (suite)"
replace wpcode = "Z00" if wpname == "UNKNOWN"
* 343 observations recoded

* Code cancelled meetings
*groups wpname if regexm(wpname, "annul")
replace wpcode = "Z00" if regexm(wpname, "annul")

* Code meetings in Press Room
*groups wpname if regexm(wpname, "[Ss]alle.*[Pp]ress")
replace wpcode = "Z00" if regexm(wpname, "[Ss]alle.*[Pp]ress")
*groups wpname if regexm(wpname, "SALLE.*PRESS")
replace wpcode = "Z00" if regexm(wpname, "SALLE.*PRESS")
*groups wpname if regexm(wpname, "Salon")
replace wpcode = "Z00" if regexm(wpname, "Salon")
*groups wpname if regexm(wpname, "SALON")
replace wpcode = "Z00" if regexm(wpname, "SALON")
*groups wpname if regexm(wpname, "RENCONTRE")
replace wpcode = "Z00" if regexm(wpname, "RENCONTRE")

* Identify and drop exact duplicates
duplicates report
duplicates list
duplicates drop
* 91 observations dropped


* Standardize format of meeting title
*************************************

* Remove consecutive blanks
replace wpname = itrim(wpname)
* Remove leading blanks
replace wpname = ltrim(wpname)
* Remove trailing blanks
replace wpname = rtrim(wpname)

* Insert blanks before and after slash where missing
*groups wpname if regexm(wpname, "(^.*[A-Z\.:])(\/)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\/)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\/)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\/)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\/)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\/)([A-Z].*)")
	
* Insert blank before slash where missing
*groups wpname if regexm(wpname, "(^.*[A-Z\.:])(\/ [A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z\.:])(\/ [A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z\.:])(\/ [A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z\.:])(\/ [A-Z].*)")	
	
* Insert blank after slash where missing
**groups wpname if regexm(wpname, "(^.* \/)([A-Z].*)"), order(h) miss

* Insert blank before parenthesis where missing
*groups wpname if regexm(wpname, "(^.*[A-Z\.:])(\(.*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z\.:])(\(.*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z\.:])(\(.*)")
	
* Correct location of fullstop
*groups wpname if regexm(wpname, "(^.*[A-Z])( \.)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + ". " + regexs(3) /*
	*/ if regexm(wpname, "(^.*[A-Z])( \.)([A-Z].*)")

* Delete ./.
*groups wpname if regexm(wpname, " \.\.\/\."), order(h) miss
replace wpname = regexr(wpname, " \.\.\/\.", "")
*groups wpname if regexm(wpname, " \.\/\."), order(h) miss
replace wpname = regexr(wpname, " \.\/\.", "")
*groups wpname if regexm(wpname, "\.\/\."), order(h) miss
replace wpname = regexr(wpname, "\.\/\.", "")
*groups wpname if regexm(wpname, "\. \/\."), order(h) miss
replace wpname = regexr(wpname, "\. \/\.", "")
*groups wpname if regexm(wpname, "\. \/ \."), order(h) miss
replace wpname = regexr(wpname, "\. \/ \.", "")

* Delete repeated fullstops
*groups wpname if regexm(wpname, "\.\."), order(h) miss
replace wpname = regexr(wpname, "\.\.", "\. ")

* Insert blank after fullstop
*groups wpname if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z][A-Z]\.)([A-Z].*)")
 
* Delete orphan full stop
*groups wpname if regexm(wpname, " \."), order(h) miss
replace wpname = regexr(wpname, " \.", "")
**
*groups wpname if regexm(wpname, "\\\.$"), order(h) miss
replace wpname = regexr(wpname, "\\\.$", "")
*groups wpname if regexm(wpname, "\\\. "), order(h) miss
replace wpname = regexr(wpname, "\\\. ", "")

* Correct other idiosyncratic observations
replace wpname = regexr(wpname, "QUESTIONS SOCIALES\.", "QUESTIONS SOCIALES")
replace wpname = regexr(wpname, "OFFRES PUBLIQUES ACQUIS\.", "OFFRES PUBLIQUES ACQUIS")
replace wpname = regexr(wpname, "COMITE BUDGET\.", "COMITE BUDGET")
	
* Insert blank after dash where missing
*groups wpname if regexm(wpname, "(^.* \-)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.* \-)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.* \-)([A-Z].*)")
	
* Insert blank before dash where missing
*groups wpname if regexm(wpname, "(^.*[A-Z])(\- [A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z])(\- [A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z])(\- [A-Z].*)")

* Insert blanks before and after slash where missing
*groups wpname if regexm(wpname, "(^.*[A-Z\.:])(\-)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\-)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\-)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\-)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\-)([A-Z].*)")

* Insert blanks before and after plus sign where missing
*groups wpname if regexm(wpname, "(^.*[A-Z\.:])(\+)([A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\+)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\+)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\+)([A-Z].*)")	
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\+)([A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) + " " + regexs(3) /*
	*/ if regexm(wpname, "(^.*)(\+)([A-Z].*)")
	
* Insert blank after dash where missing
**groups wpname if regexm(wpname, "(^.* \+)([A-Z].*)"), order(h) miss
	
* Insert blank before plus sign where missing
*groups wpname if regexm(wpname, "(^.*[A-Z])(\+ [A-Z].*)"), order(h) miss
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z])(\+ [A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z])(\+ [A-Z].*)")
replace wpname = regexs(1) + " " + regexs(2) /*
	*/ if regexm(wpname, "(^.*[A-Z])(\+ [A-Z].*)")
	
* Delete @
*groups wpname if regexm(wpname, " @"), order(h) miss
replace wpname = regexr(wpname, " @", "")
*groups wpname if regexm(wpname, "@"), order(h) miss
replace wpname = regexr(wpname, "@", "")

* Delete blank after opening parenthesis
*groups wpname if regexm(wpname, "\( "), order(h) miss
replace wpname = regexr(wpname, "\( ", "(")

* Delete (SUITE)
*groups wpname if regexm(wpname, " \(SUITE\)"), order(h) miss
replace wpname = regexr(wpname, " \(SUITE\)", "")
*groups wpname if regexm(wpname, "\(SUITE.*\)"), order(h) miss
replace wpname = regexr(wpname, "\(SUITE.*\)", "")
*groups wpname if regexm(wpname, " \(suite\)"), order(h) miss
replace wpname = regexr(wpname, " \(suite\)", "")
*groups wpname if regexm(wpname, "\(suite\)"), order(h) miss
replace wpname = regexr(wpname, "\(suite\)", "")
**
*groups wpname if regexm(wpname, "suite, "), order(h) miss
replace wpname = regexr(wpname, "suite, ", "")
*groups wpname if regexm(wpname, ", suite"), order(h) miss
replace wpname = regexr(wpname, ", suite", "")
*groups wpname if regexm(wpname, " -suite"), order(h) miss
replace wpname = regexr(wpname, " -suite", "")
*groups wpname if regexm(wpname, " \(suite �vt\)"), order(h) miss
replace wpname = regexr(wpname, " \(suite .vt\)", "")
*groups wpname if regexm(wpname, "suite"), order(h) miss

* Delete forward slashes
*groups wpname if regexm(wpname, "\\"), order(h) miss
replace wpname = regexr(wpname, "\\", "")

* Delete blank before closing parenthesis
*groups wpname if regexm(wpname, " \)"), order(h) miss
replace wpname = regexr(wpname, " \)", ")")


* Delet prefixes
****************

* Delete second colon directly after first one
*groups wpname if regexm(wpname, "::"), order(h) miss
replace wpname = regexr(wpname, "::", ":")
replace wpname = regexr(wpname, "::", ":")

* Delete room numbers and other pre-fixes of observations with two colons
*groups wpname if regexm(wpname, "(^.*:)(.*:.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^.*:)(.*:.*)")
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^.*:)(.*:.*)")
	
* Delete 'Salle' room number
*groups wpname if regexm(wpname, "(^[Ss][Aa][Ll][Ll][Ee].*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[Ss][Aa][Ll][Ll][Ee].*:)(.*)")

* Delete 'sdp' room number
*groups wpname if regexm(wpname, "(^[Ss][Dd][Pp].*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[Ss][Dd][Pp].*:)(.*)")
	
* Delete KO prefix
*groups wpname if regexm(wpname, "(^KO ?:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^KO ?:)(.*)")
	
* Delete room number that ends with a colon
*groups wpname if regexm(wpname, "(^[0-9].*[0-9] ?:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[0-9].*[0-9] ?:)(.*)")

* Delete Borschette room number
*groups wpname if regexm(wpname, "(^BORSCHETTE.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^BORSCHETTE.*:)(.*)")

*groups wpname if regexm(wpname, "(^BORSCHETTE [0-9][A-Z] )(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^BORSCHETTE [0-9][A-Z] )(.*)")	
	
*groups wpname if regexm(wpname, "(^Centre Borschette.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^Centre Borschette.*:)(.*)")	

* Keep information about international organizations before deleting locations
*groups wpname if regexm(wpname, "(^[A-Z][a-z].*OCDE ?:)(.*)"), order(h) miss
replace wpname = regexr(wpname, "^[A-Z][a-z].*OCDE ?:", "OCDE:")
*groups wpname if regexm(wpname, "(^[A-Z][a-z].*FAO ?:)(.*)"), order(h) miss
replace wpname = regexr(wpname, "^[A-Z][a-z].*FAO ?:", "FAO:")
*groups wpname if regexm(wpname, "(^[A-Z][a-z].*ACP ?:)(.*)"), order(h) miss
replace wpname = regexr(wpname, "^[A-Z][a-z].*ACP ?:", "ACP:")

* Delete locations that end with a colon
*groups wpname if regexm(wpname, "(^[A-Z][a-z ]+:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[A-Z][a-z ]+:)(.*)")
	
* Delete remaining locations and other room numbers that end with a colon
*groups wpname if regexm(wpname, "(^[A-Z][a-z].*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[A-Z][a-z].*:)(.*)")
	
* Delete Kortenberg location
*groups wpname if regexm(wpname, "(^KO.*:)(.*)"), order(h) miss
replace wpname = regexr(wpname, "KO GR. TR. CTE MILIT. /: ", "KO: GR. TR. CTE MILIT. /") 
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^KO.*:)(.*)")
	
* Delete Egmont location
*groups wpname if regexm(wpname, "(EGMONT)(.*)"), order(h) miss
replace wpname = regexr(wpname, "PALAIS EGMONT GR. SALLE 113 CECA", "PALAIS EGMONT GR. SALLE: 113 CECA") 

*groups wpname if regexm(wpname, "(.*EGMONT.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(.*EGMONT.*:)(.*)")
	
*groups wpname if regexm(wpname, "(\(.*EGMONT.*\))(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(\(.*EGMONT.*\))(.*)")
	
* Delete SALLE PRES pre-fix
*groups wpname if regexm(wpname, "^SALLE PRES[\. ]( [0-9] )?"), order(h) miss
replace wpname = regexr(wpname, "^SALLE PRES[\. ]( [0-9] )?", "")

*groups wpname if regexm(wpname, "^Salle [Pp]r.s\. ( [0-9] )?"), order(h) miss
replace wpname = regexr(wpname, "^Salle [Pp]r.s\. ( [0-9] )?", "")

*groups wpname if regexm(wpname, "(.*salle.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(.*salle.*:)(.*)")
	
* Delete 'niv' pre-fix
*groups wpname if regexm(wpname, "(^niv.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^niv.*:)(.*)")
	
* Delete 'RP' pre-fix
*groups wpname if regexm(wpname, "(^RP.*:)(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^RP.*:)(.*)")
	
* Delete 'SG' pre-fix
*groups wpname if regexm(wpname, "(^SG.*:)(.*)"), order(h) miss	
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^SG.*:)(.*)")
	
* Delete 'Strasbourg' location
*groups wpname if regexm(wpname, "STRASBOURG ?:? ?"), order(h) miss	
replace wpname = regexr(wpname, "STRASBOURG ?:? ?", "")
	
* Delete 'Luxembourg' location
*groups wpname if regexm(wpname, "LUXEMBOURG ?:? ?"), order(h) miss	
replace wpname = regexr(wpname, "LUXEMBOURG ?:? ?", "")
replace wpname = regexr(wpname, "\(\) : ", "")
	
* Delete 'RESERVEE'
*groups wpname if regexm(wpname, "RESERVEE:? ?"), order(h) miss
replace wpname = regexr(wpname, "RESERVEE:? ?", "")


* Delete suffixes
*****************

* Delete 'vt.' suffix
*groups wpname if regexm(wpname, " ?\(.*vtl?\.?\)"), order(h) miss
replace wpname = regexr(wpname, " ?\(.*vtl?\.?\)", "")

*groups wpname if regexm(wpname, " .vtl?.?"), order(h) miss
replace wpname = regexr(wpname, " .vtl?.?", "")

* Delete 'matin' suffix
*groups wpname if regexm(wpname, "\(.*matin.*\)"), order(h) miss
replace wpname = regexr(wpname, "\(.*matin.*\)", "")

*groups wpname if regexm(wpname, " matin"), order(h) miss
replace wpname = regexr(wpname, " matin", "")

* Delete 'am' suffix
*groups wpname if regexm(wpname, "\(.*a\.?m\.?\)"), order(h) miss
replace wpname = regexr(wpname, "\(.*a\.?m\.?\)", "")

*groups wpname if regexm(wpname, " ?a\.?m\.?"), order(h) miss
replace wpname = regexr(wpname, " ?a\.?m\.?", "")

* Delete number suffix
*groups wpname if regexm(wpname, " ?\(.*\+ ?[0-9].*\)"), order(h) miss
replace wpname = regexr(wpname, " ?\(.*\+ ?[0-9].*\)", "")

* Remove consecutive blanks
replace wpname = itrim(wpname)
* Remove leading blanks
replace wpname = ltrim(wpname)
* Remove trailing blanks
replace wpname = rtrim(wpname)


* Delete session numbers of meetings
************************************

* Delete session number
*groups wpname if regexm(wpname, "(^[0-9]+ ?[Ee]?[Mm]?[Ee])(.*)"), order(h) miss
replace wpname = regexs(2) /*
	*/ if regexm(wpname, "(^[0-9]+ ?[Ee]?[Mm]?[Ee])(.*)")	


* Replace common abbreviations with complete term
*************************************************
	
* Recode 'Attaches'
*groups wpname if regexm(wpname, "ATT "), order(h) miss
replace wpname = regexr(wpname, "ATT ", "ATTACHES ")

*groups wpname if regexm(wpname, "ATTACH\."), order(h) miss
replace wpname = regexr(wpname, "ATTACH\.", "ATTACHES")

*groups wpname if regexm(wpname, "ATT\."), order(h) miss
replace wpname = regexr(wpname, "ATT\.", "ATTACHES")

* Recode 'Conseillers'
*groups wpname if regexm(wpname, "CONSEILL\."), order(h) miss
replace wpname = regexr(wpname, "CONSEILL\.", "CONSEILLERS")

*groups wpname if regexm(wpname, "CONS\."), order(h) miss
replace wpname = regexr(wpname, "CONS\.", "CONSEILLERS")

* Recode 'Comite'
*groups wpname if regexm(wpname, "^CTE "), order(h) miss
replace wpname = regexr(wpname, "^CTE ", " COMITE ")

*groups wpname if regexm(wpname, " CTE "), order(h) miss
replace wpname = regexr(wpname, " CTE ", " COMITE ")

*groups wpname if regexm(wpname, "CTE\."), order(h) miss
replace wpname = regexr(wpname, "CTE\.", "COMITE")

* Recode 'Agri'
*groups wpname if regexm(wpname, "AGRICOLES"), order(h) miss
replace wpname = regexr(wpname, "AGRICOLES", "AGRI")
replace wpname = regexr(wpname, "AGRICOLES", "AGRI")

*groups wpname if regexm(wpname, "AGRICOLE"), order(h) miss
replace wpname = regexr(wpname, "AGRICOLE", "AGRI")

*groups wpname if regexm(wpname, "AGRICULTURE"), order(h) miss
replace wpname = regexr(wpname, "AGRICULTURE", "AGRI")

*groups wpname if regexm(wpname, "AGRI\."), order(h) miss
replace wpname = regexr(wpname, "AGRI\.", "AGRI")

* Recode 'Coordination'
*groups wpname if regexm(wpname, "COORD "), order(h) miss
replace wpname = regexr(wpname, "COORD ", "COORDINATION ")

*groups wpname if regexm(wpname, "COORD$"), order(h) miss
replace wpname = regexr(wpname, "COORD$", "COORDINATION")

*groups wpname if regexm(wpname, "COORD\)"), order(h) miss
replace wpname = regexr(wpname, "COORD\) ", "COORDINATION\)")

*groups wpname if regexm(wpname, "COORD\."), order(h) miss
replace wpname = regexr(wpname, "COORD\.", "COORDINATION")

* Recode 'Affairs'
*groups wpname if regexm(wpname, "AFF\."), order(h) miss
replace wpname = regexr(wpname, "AFF\.", "AFFAIRES")

* Recode 'Conjoint'
*groups wpname if regexm(wpname, "CONJ "), order(h) miss
replace wpname = regexr(wpname, "CONJ ", "CONJOINT ")

*groups wpname if regexm(wpname, "CONJ\."), order(h) miss
replace wpname = regexr(wpname, "CONJ\.", "CONJOINT")

* Recode 'Questions'
*groups wpname if regexm(wpname, "Q\."), order(h) miss
replace wpname = regexr(wpname, "Q\.", "QUESTIONS")

*groups wpname if regexm(wpname, "QU\."), order(h) miss
replace wpname = regexr(wpname, "LIQU. BANQUES", "LIQUIDATION BANQUES")
replace wpname = regexr(wpname, "QU\.", "QUESTIONS")

*groups wpname if regexm(wpname, "QUEST "), order(h) miss
replace wpname = regexr(wpname, "QUEST ", "QUESTIONS ")

*groups wpname if regexm(wpname, "QUEST\."), order(h) miss
replace wpname = regexr(wpname, "QUEST\.", "QUESTIONS")
replace wpname = regexr(wpname, "QUEST\.", "QUESTIONS")

* Recode 'Recherche'
*groups wpname if regexm(wpname, "RECH "), order(h) miss
replace wpname = regexr(wpname, "RECH ", "RECHERCHE ")

*groups wpname if regexm(wpname, "RECH\."), order(h) miss
replace wpname = regexr(wpname, "RECH\.", "RECHERCHE")

* Recode 'Groupe'
*groups wpname if regexm(wpname, "^GR "), order(h) miss
replace wpname = regexr(wpname, "^GR ", "GROUPE ")

*groups wpname if regexm(wpname, " GR "), order(h) miss
replace wpname = regexr(wpname, " GR ", " GROUPE ")

*groups wpname if regexm(wpname, "^GR\."), order(h) miss
replace wpname = regexr(wpname, "^GR\.", "GROUPE")

*groups wpname if regexm(wpname, " GR\."), order(h) miss
replace wpname = regexr(wpname, " GR\.", " GROUPE")
replace wpname = regexr(wpname, " GR\.", " GROUPE")

* Recode 'Experts'
*groups wpname if regexm(wpname, "EXP\."), order(h) miss
replace wpname = regexr(wpname, "EXP\.", "EXPERTS")

* Recode 'Travail'
*groups wpname if regexm(wpname, " TR\. "), order(h) miss
replace wpname = regexr(wpname, " TR\. ", " TRAVAIL ")

* Recode 'Travail'
*groups wpname if regexm(wpname, "HTF"), order(h) miss
replace wpname = regexr(wpname, "HTF", "HEADLINE GOAL TASK FORCE")

* Recode 'Atomique'
*groups wpname if regexm(wpname, " ATO "), order(h) miss
replace wpname = regexr(wpname, " ATO ", " ATOMIQUES ")

*groups wpname if regexm(wpname, " ATOM "), order(h) miss
replace wpname = regexr(wpname, " ATOM ", " ATOMIQUES ")

*groups wpname if regexm(wpname, " ATO$"), order(h) miss
replace wpname = regexr(wpname, " ATO$", " ATOMIQUES")

*groups wpname if regexm(wpname, " ATOM$"), order(h) miss
replace wpname = regexr(wpname, " ATOM$", " ATOMIQUES")

*groups wpname if regexm(wpname, "ATO\."), order(h) miss
replace wpname = regexr(wpname, "ATO\.", "ATOMIQUES")
replace wpname = regexr(wpname, "ATO\.", "ATOMIQUES")

*groups wpname if regexm(wpname, "ATOM\."), order(h) miss
replace wpname = regexr(wpname, "ATOM\.", "ATOMIQUES")

* Recode 'Veterinaire'
*groups wpname if regexm(wpname, " VET "), order(h) miss
replace wpname = regexr(wpname, " VET ", " VETERINAIRES ")

*groups wpname if regexm(wpname, "\(VET\)"), order(h) miss
replace wpname = regexr(wpname, "\(VET\)", "\(VETERINAIRES\)")

*groups wpname if regexm(wpname, "VET\."), order(h) miss
replace wpname = regexr(wpname, "VET\.", "VETERINAIRES")

*groups wpname if regexm(wpname, "VETER\."), order(h) miss
replace wpname = regexr(wpname, "VETER\.", "VETERINAIRES")

*groups wpname if regexm(wpname, "VETERIN\."), order(h) miss
replace wpname = regexr(wpname, "VETERIN\.", "VETERINAIRES")

* Recode 'Cooeration'
*groups wpname if regexm(wpname, "COOP\."), order(h) miss
replace wpname = regexr(wpname, "COOP\.", "COOPERATION")

* Recode 'Cooeration'
*groups wpname if regexm(wpname, "DEV\."), order(h) miss
replace wpname = regexr(wpname, "DEV\.", "DEVELOPPEMENT")

* Recode 'Services'
*groups wpname if regexm(wpname, "SERV\."), order(h) miss
replace wpname = regexr(wpname, "SERV\.", "SERVICES")

*groups wpname if regexm(wpname, "SERVICE "), order(h) miss
replace wpname = regexr(wpname, "SERVICE ", "SERVICES ")

* Recode 'Militaire'
*groups wpname if regexm(wpname, "MIL "), order(h) miss
replace wpname = regexr(wpname, "MIL ", "MILITAIRE ")

*groups wpname if regexm(wpname, "MIL\."), order(h) miss
replace wpname = regexr(wpname, "MIL\.", "MILITAIRE")

*groups wpname if regexm(wpname, "MILIT\."), order(h) miss
replace wpname = regexr(wpname, "MILIT\.", "MILITAIRE")

* Recode 'Europe'
*groups wpname if regexm(wpname, "^EUR "), order(h) miss
replace wpname = regexr(wpname, "^EUR ", "EUROPE ")

*groups wpname if regexm(wpname, "EUR\."), order(h) miss
replace wpname = regexr(wpname, "EUR\.", "EUROPE")
replace wpname = regexr(wpname, "EUR\.", "EUROPE")

* Recode 'Centrale'
*groups wpname if regexm(wpname, "CENT\."), order(h) miss
replace wpname = regexr(wpname, "CENT\.", "CENTRALE")

*groups wpname if regexm(wpname, "CENTR\."), order(h) miss
replace wpname = regexr(wpname, "CENTR\.", "CENTRALE")

*groups wpname if regexm(wpname, "CENTR "), order(h) miss
replace wpname = regexr(wpname, "CENTR ", "CENTRALE ")

*groups wpname if regexm(wpname, "CENTR$"), order(h) miss
replace wpname = regexr(wpname, "CENTR$", "CENTRALE")

*groups wpname if regexm(wpname, "CENTRAL$"), order(h) miss
replace wpname = regexr(wpname, "CENTRAL$", "CENTRALE")

* Recode 'Orientale'
*groups wpname if regexm(wpname, "EUROPE ORIENT "), order(h) miss
replace wpname = regexr(wpname, "EUROPE ORIENT ", "EUROPE ORIENTALE ")

*groups wpname if regexm(wpname, "EUROPE ORIENTAL "), order(h) miss
replace wpname = regexr(wpname, "EUROPE ORIENTAL ", "EUROPE ORIENTALE ")

*groups wpname if regexm(wpname, "EUROPE OR\."), order(h) miss
replace wpname = regexr(wpname, "EUROPE OR\.", "EUROPE ORIENTALE")

*groups wpname if regexm(wpname, "EUROPE ORIEN\."), order(h) miss
replace wpname = regexr(wpname, "EUROPE ORIEN\.", "EUROPE ORIENTALE")

*groups wpname if regexm(wpname, "EUROPE ORIENT\."), order(h) miss
replace wpname = regexr(wpname, "EUROPE ORIENT\.", "EUROPE ORIENTALE")

*groups wpname if regexm(wpname, "EUROPE OR"), order(h) miss
replace wpname = regexr(wpname, "EUROPE ORIENT ", "EUROPE ORIENTALE ")

* Remove 'informelle'
*groups wpname if regexm(wpname, "^INF\. "), order(h) miss
replace wpname = regexr(wpname, "^INF\. ", "")
*groups wpname if regexm(wpname, "INF\.$"), order(h) miss
replace wpname = regexr(wpname, "^INF\.$", "")

*groups wpname if regexm(wpname, "^INFORM\.? "), order(h) miss
replace wpname = regexr(wpname, "^INFORM\.? ", "")

*groups wpname if regexm(wpname, "INFORMEL\.? "), order(h) miss
replace wpname = regexr(wpname, "INFORMEL\.? ", "")

*groups wpname if regexm(wpname, "INFORMELLE "), order(h) miss
replace wpname = regexr(wpname, "INFORMELLE ", "")
replace wpname = regexr(wpname, " - INFORMELLE", "")


* Code empty observations
list wpcode wpname wpname_orig if wpname == ""
replace wpcode = "Z00" if wpname == ""
list wpname wpname_orig if wpname == ")"
replace wpcode = "Z00" if wpname == ")"


* Code other types of meetings
******************************

* Code briefing meetings
*groups wpname if regexm(wpname, "BRIEFING"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "BRIEFING")
* 945 observations dropped (almost all Coreper 1 and 2 briefings)
* 18
*groups wpname if regexm(wpname, "BRIEF\."), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "BRIEF.")
* 14 observations dropped (briefings of various sorts, especially Coreper and PSC)
* 2

* Code press conference meetings
*groups wpname if regexm(wpname, "CONFERENCE DE PRESSE"), order(h) miss show(f F)
replace wpcode = "Z00" if regexm(wpname, "CONFERENCE DE PRESSE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONF.* PRESS"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONF.* PRESS")

* Code conciliation committee meetings
*groups wpname if regexm(wpname, "CONCILIATION"), order(h) miss show(f F)
replace wpcode = "Z00" if regexm(wpname, "CONCILIATION")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONCIL"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONCIL")

* Code trilogue meetings
*groups wpname if regexm(wpname, "TRILOGUE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "TRILOGUE")

* Code seminar meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "SEMIN"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "SEMIN")

* Code intergovernmental conferences
*groups wpname if wpcode != "Z00" & regexm(wpname, "CIG"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" &  regexm(wpname, "CIG")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONF.*INT.*GOUV"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" &  regexm(wpname, "CONF.*INT.*GOUV")
*groups wpname if wpcode != "Z00" & regexm(wpname, "INT.*GOUV"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" &  regexm(wpname, "INT.*GOUV")

* Code Constitutional Convention meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONVENTION EUROP"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONVENTION EUROP")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONV.* GROUPE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONV.* GROUPE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "PRAESIDIUM"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "PRAESIDIUM")

* Fundamental Rights Charter meetings (up to 2 October 2000)
*list date wpname if wpcode != "Z00" & regexm(wpname, "DR.*FOND")
*groups wpname if wpcode != "Z00" & date <= d(02oct2000) & regexm(wpname, "DR.*FOND"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & date <= d(02oct2000) & regexm(wpname, "DR.*FOND")

* Code Brussels Convention meeting
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONV.*BRUX"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONV.*BRUX")

* Code Dublin Convention meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONV.*DUB"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONV.*DUB")

* Code Bankruptcy Convention meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "FAILLITE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "FAILLITE")

* Code Energy Charter meetings
list date wpname if wpcode != "Z00" & regexm(wpname, "CHART.*ENERG")
* Exists after 1999 but nowhere mentioned in list of preparatory bodies
*groups wpname if wpcode != "Z00" & regexm(wpname, "CHART.*ENERG"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CHART.*ENERG")

* Code accession conferences
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONF.*ADH"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONF.*ADH")

* Code COST meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "COST( |$)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "COST( |$)")

* Code signature meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "SIGNATURE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "SIGNATURE")

* Code Barcelona process meetings
list date wpname if wpcode != "Z00" & regexm(wpname, "EURO.*MED")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EURO.*MED"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EURO.*MED")
*groups wpname if wpcode != "Z00" & regexm(wpname, "(MASH)|(TERR)") == 0 /*
	*/ & regexm(wpname, "PROC.* BARC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(MASH)|(TERR)") == 0 /*
	*/ & regexm(wpname, "PROC.* BARC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "(MASH)|(TERR)") == 0 /*
	*/ & regexm(wpname, "BARC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(MASH)|(TERR)") == 0 /*
	*/ & regexm(wpname, "BARC")

* Code EU-NATO ad hoc working parties (10025-00 Rev.1)
*groups wpname if wpcode != "Z00" & regexm(wpname, "UE.*OTAN") /*
	*/ & regexm(wpname, "(AD HOC)|(CAP)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "UE.*OTAN") /*
	*/ & regexm(wpname, "(AD HOC)|(CAP)")
	
* Code meetings of 'like-minded countries' in CFSP (probably briefings by the Presidency;
* or meetings with group of developing countries, see http://en.wikipedia.org/wiki/Like_Minded_Group)
list date wpname if wpcode != "Z00" & regexm(wpname, "LIKE MINDED")
*groups wpname if wpcode != "Z00" & regexm(wpname, "LIKE MINDED"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "LIKE MINDED")

* Code Athena Special Committee meeting (deals with financing of military operations)
* http://www.consilium.europa.eu/uedocs/cms_data/docs/pressdata/EN/foraff/139880.pdf
*groups wpname if wpcode != "Z00" & regexm(wpname, "ATHENA"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ATHENA")

* Code conference meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONFERENCE INTERNE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONFERENCE INTERNE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONFERENCE EXTERNE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONFERENCE EXTERNE")

* Code Eurogroup meetings
*list date wpname if wpcode != "Z00" & regexm(wpname, "EUROGROUPE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUROGROUPE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EUROGROUPE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "ZONE EURO"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ZONE EURO")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUROGROUP"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EUROGROUP")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EURO "), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EURO ")

* Code international conferences
list date wpname if wpcode != "Z00" & regexm(wpname, "MONDIAL")
*groups wpname if wpcode != "Z00" & regexm(wpname, "MONDIAL"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "MONDIAL")

* Code Civil Military Co-ooperation conference
list date wpname if wpcode != "Z00" & regexm(wpname, "CIMIC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CIMIC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CIMIC")

* Code European diplomatic programme
*list date wpname if wpcode != "Z00" & regexm(wpname, "DIPLOMATIQUE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "DIPLOMATIQUE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "DIPLOMATIQUE")

* Code UN Trade and Development conference
*La Conf�rence des Nations unies sur le Commerce et le D�veloppement 
*list date wpname if wpcode != "Z00" & regexm(wpname, "^CNUCED")
*groups wpname if wpcode != "Z00" & regexm(wpname, "^CNUCED"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "^CNUCED")
	
* Ad hoc European Solidarity Fund
*list date wpname if wpcode != "Z00" & regexm(wpname, "AD HOC FOND EUROPEEN.*SOLIDARITE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "AD HOC FOND EUROPEEN.*SOLIDARITE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "AD HOC FOND EUROPEEN.*SOLIDARITE")

* Preparation for ASEM conference
*list date wpname if wpcode != "Z00" & regexm(wpname, "ASEM")
*groups wpname if wpcode != "Z00" & regexm(wpname, "ASEM"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ASEM")

* National armaments directors representatives (European Defence Agency)
*groups wpname if wpcode != "Z00" & regexm(wpname, "NAT. ARMAMENTS DIRECTORS REPR. \(NADREP\)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "NAT. ARMAMENTS DIRECTORS REPR. \(NADREP\)")
*groups wpname if wpcode != "Z00" & regexm(wpname, " EDA"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, " EDA")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EDA "), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EDA ")
*groups wpname if wpcode != "Z00" & regexm(wpname, "AGENCE EUROPEENNE DE LA DEFENSE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "AGENCE EUROPEENNE DE LA DEFENSE")

* Police workshop
*groups wpname if wpcode != "Z00" & regexm(wpname, "POLICE WORKSHOP"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "POLICE WORKSHOP")

* Situation Centre conference
*groups wpname if wpcode != "Z00" & regexm(wpname, "SITCEN"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "SITCEN")

* EU Headquarters conference
*groups wpname if wpcode != "Z00" & regexm(wpname, "EU ((HQs)|(HEADQUARTES)) CONFERENCE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EU ((HQs)|(HEADQUARTES)) CONFERENCE")

* Peace Implementation Conference (Bosnia-Herzegovina, see http://www.ohr.int/pic/archive.asp?sa=on)
*groups wpname if wpcode != "Z00" & regexm(wpname, "PEACE IMPLEMENTATION CONF"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "PEACE IMPLEMENTATION CONF")

* Board of Governors and Committee of Inquiry for Anna Lindh Foundation
*groups wpname if wpcode != "Z00" & regexm(wpname, "LINDH"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "LINDH")
	
* Conference du Mercredi
*groups wpname if wpcode != "Z00" & regexm(wpname, "MERCREDI"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "MERCREDI")
	
* Newcomers training
*groups wpname if wpcode != "Z00" & regexm(wpname, "NEWCOMERS LECTURES"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "NEWCOMERS LECTURES")

* Kosovo workshop and other Kosovo related meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "KOSOVO"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "KOSOVO")

* AMIS (AU in Sudan mission) workshop
*groups wpname if wpcode != "Z00" & regexm(wpname, "WORKSHOP AMIS"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "WORKSHOP AMIS")

* ESDP orientation course and conference
*groups wpname if wpcode != "Z00" & regexm(wpname, "ESDP.*((COURSE)|(CONF))"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ESDP.*((COURSE)|(CONF))")
	
* EU-Golf cooperation
*groups wpname if wpcode != "Z00" & regexm(wpname, "GULF COOP"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "GULF COOP")
**
*groups wpname if wpcode != "Z00" & regexm(wpname, "UE - GCC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "UE - GCC")

* ESDC (European Security and Defence College)
*groups wpname if wpcode != "Z00" & regexm(wpname, "ESDC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ESDC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUROPEAN SECURITY AND DEFENCE COLLEGE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EUROPEAN SECURITY AND DEFENCE COLLEGE")

* Union for the Mediterranian coordination meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "MEDIT") /*
	*/ & regexm(wpname, "(MASH)|(PROD)|(PESC)") == 0, order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "MEDIT") /*
	*/ & regexm(wpname, "(MASH)|(PROD)|(PESC)") == 0
**
* Code coordination meeting
*groups wpname if wpcode != "Z00" & regexm(wpname, "NON ARAB"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "NON ARAB")

* Working party on Police and Justice
*(set up by the Conference of the European Data Protection Autorities)
*groups wpname if wpcode != "Z00" & regexm(wpname, "POLICE.*JUST"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "POLICE.*JUST")
*groups wpname if wpcode != "Z00" & regexm(wpname, "WPPJ"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "WPPJ")

* ITER task force
*(26 May - 25 June 2010, set up by Presidency to investigate financial situation of 
* thermonuclear reactor development)
*groups wpname if wpcode != "Z00" & regexm(wpname, "ITER TASK FORCE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "ITER TASK FORCE")

* World trade organisation meeting
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONFERENCE MINISTERIELLE O.M.C."), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONFERENCE MINISTERIELLE O.M.C.")
*groups wpname if wpcode != "Z00" & regexm(wpname, "MINIST. OMC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "MINIST. OMC")

* Exercise Study EST06 (see CM 3596/06)
*groups wpname if wpcode != "Z00" & regexm(wpname, "EXERCISE STUDY EST 06"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "EXERCISE STUDY EST 06")

* Code Macro-economic dialogue meetings
* Between Commission, Council, ECP and social partners, see 12223/99
*list date wpname if wpcode != "Z00" & regexm(wpname, "DIALOGUE MACROECONOMIQUE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "DIALOGUE MACROECONOMIQUE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "DIALOGUE MACROECONOMIQUE") 

* Code Joint Supervision Board of EUROPOL
*groups wpname if wpcode != "Z00" & regexm(wpname, "(J\.?S\.?B)|(APPEAL.*COM)|(COMITE.*APPEL)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(J\.?S\.?B)|(APPEAL.*COM)|(COMITE.*APPEL)")

* Code Joint Supervision Authority of Schengen
*AUTORITE CONTROLE COMMUNE
*groups wpname if wpcode != "Z00" & regexm(wpname, "(J\.?S\.?A)|(A\.C\.?C)|(AUT.*CONTR.*COM)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(J\.?S\.?A)|(A\.C\.?C)|(AUT.*CONTR.*COM)")

* Code OECD coordination meetings
* They seem to be only recorded before October 2000
* Except for Agriculture, there is no particular working party dealing with OECD coordination
*list date wpname if wpcode != "Z00" & regexm(wpname, "COORD.*(OECD)|(OCDE)") /*
	*/ | regexm(wpname, "(OECD)|(OCDE).*COORD")
*groups wpname if wpcode != "Z00" & regexm(wpname, "COORD.*(OECD)|(OCDE)") /*
	*/ | regexm(wpname, "(OECD)|(OCDE).*COORD"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "COORD.*(OECD)|(OCDE)") /*
	*/ | regexm(wpname, "(OECD)|(OCDE).*COORD")
	
* Code OECD multilateral investment treaty
*groups wpname if wpcode != "Z00" & regexm(wpname, "(MULT.*INV)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(MULT.*INV)")

* Code Commodities summit meetings
* Only recorded pre-1999
*list date wpname if wpcode != "Z00" & regexm(wpname, "(PROD.*BAS)|(PROBA)") /*
	*/ & regexm(wpname, "(SUMMIT)|(SOMMET)")
*groups wpname if wpcode != "Z00" & regexm(wpname, "(PROD.*BAS)|(PROBA)") /*
	*/ & regexm(wpname, "(SUMMIT)|(SOMMET)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(PROD.*BAS)|(PROBA)") /*
	*/ & regexm(wpname, "(SUMMIT)|(SOMMET)")

* Code remaining summits and preparation meetings (not clear who does the preparing)
*groups wpname if wpcode != "Z00" & regexm(wpname, "(SUMMIT)|(SOMMET)"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "(SUMMIT)|(SOMMET)")
	
* Code EU-LAC cooperation
* European Union and the Latin America and the Caribbean co-operation 
* EU - Latin American Countries meeting
* Three areas of cooperation: Drugs, Migration, Research and Innovation
*list date wpname if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "DROGUE")	
*groups wpname if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "DROGUE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "DROGUE")
	
*list date wpname if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "MIGR")	
*groups wpname if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "MIGR"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "LAC") /*
	*/ & regexm(wpname, "MIGR")	
	
*list date wpname if wpcode != "Z00" & regexm(wpname, "LAC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "LAC"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "LAC")	

* EU - Andean Community dialogue on Drugs
*list date wpname if wpcode != "Z00" & regexm(wpname, " ANDES")
*groups wpname if wpcode != "Z00" & regexm(wpname, " ANDES"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, " ANDES")

* Trilateral sugar
* Probably some kind of trade negotiations
*list date wpname if wpcode != "Z00" & regexm(wpname, "TRILATERALES SUCRE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "TRILATERALES SUCRE"), order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "TRILATERALES SUCRE")

* Code troika meetings
*list date wpname if wpcode != "Z00" & regexm(wpname, "TROIKA")
*groups wpname if wpcode != "Z00" & regexm(wpname, "TROIKA"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "TROIKA")
* 1354 observations deleted
*list date wpname if wpcode != "Z00" & regexm(wpname, "TRK")
*groups wpname if regexm(wpname, "TRK"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "TRK")
* 16 observations deleted
*list date wpname if wpcode != "Z00" & regexm(wpname, "TRK")
*groups wpname if regexm(wpname, "TKA"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "TKA")
* 67 observations deleted

* Code political dialogue meetings
*list date wpname if wpcode != "Z00" & regexm(wpname, "(^| )DIAL")
*groups wpname if wpcode != "Z00" & regexm(wpname, "(^| )DIAL"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "(^| )DIAL")

* Code meetings parallel to Council
*list date wpname if wpcode != "Z00" & regexm(wpname, "GR.* PARA")
*groups wpname if wpcode != "Z00" & regexm(wpname, "GR.* PARA"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "GR.* PARA")

* Code forum meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "FORUM"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "FORUM")

**
* Code European Council meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONSEIL EURO"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "CONSEIL EURO")
*groups wpname if wpcode != "Z00" & regexm(wpname, "PRESIDENT CE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "PRESIDENT CE")

* Code EEAS meeting
*groups wpname if wpcode != "Z00" & regexm(wpname, "EEAS"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EEAS")

* Code Council of European Energy Regulators and 
* Strategic Forum for International Sciencen and Technology Cooperation meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CEER"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "CEER")

* Code European Union Institute for Security Studies meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "ISS"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EUISS")
*groups wpname if wpcode != "Z00" & regexm(wpname, "POLICY PLANNERS"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "POLICY PLANNERS")
*groups wpname if wpcode != "Z00" & regexm(wpname, "INST.* SEC.* STUD"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "INST.* SEC.* STUD")
*groups wpname if wpcode != "Z00" & regexm(wpname, " ISS$"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, " ISS$")
*groups wpname if wpcode != "Z00" & regexm(wpname, "ISS "), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "ISS ")

* Code European Union Satellite Centre meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUSC"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EUSC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "SAT.*CEN"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "SAT.*CEN")

* Code European stability mechanism meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUROP.* STAB.* MECH"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EUROP.* STAB.* MECH")

* Code force generation and mission contributor meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "FORCES? GEN"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "FORCES? GEN")
*groups wpname if wpcode != "Z00" & regexm(wpname, "GENERATION.* FORCE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "GENERATION.* FORCE")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONTRIBUT"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "CONTRIBUT")
groups wpname if wpcode != "Z00" & regexm(wpname, "C[o|O]C") & regexm(wpname, "COC[OE]N") == 0, order(h) miss
replace wpcode = "Z00" if regexm(wpname, "C[o|O]C") & regexm(wpname, "COC[OE]N") == 0

* Code Euro group meetings and of Heads of State or Government meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "ETAT"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "ETAT")
*groups wpname if wpcode != "Z00" & regexm(wpname, "REPRESENTANTS PERMANENTS"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "REPRESENTANTS PERMANENTS")

* Remove G7 meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "G7"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "G7")

* Code task force and sherpa meetings
*groups wpname if wpcode != "Z00" & wpname == "TASK FORCE", order(h) miss
replace wpcode = "Z00" if wpname == "TASK FORCE"
*groups wpname if wpcode != "Z00" & regexm(wpname, "SHERPA"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "SHERPA")

* Code inter-institutional Foreign Affairs Council preparations
*groups wpname if wpcode != "Z00" & regexm(wpname, "PRE.* FAC"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "PRE.* FAC")
*groups wpname if wpcode != "Z00" & regexm(wpname, "PRE.* CAE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "PRE.* CAE")

* Code EU military staff
*groups wpname if wpcode != "Z00" & regexm(wpname, "EUMS "), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EUMS ")

* Code EU battle group meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "EU.*BG"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EU.*BG")
*groups wpname if wpcode != "Z00" & regexm(wpname, "EU BATTLE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "EU BATTLE")

* Code EU defence policy directors meeting
*groups wpname if wpcode != "Z00" & regexm(wpname, "DEFEN.E POL"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "DEFEN.E POL")

* Code cooperation council meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONSEIL( DE)? COOP"), order(h) miss
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONSEIL( DE)? COOP")

* Code Association and Stabilization Council
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONSEIL( DE)? STAB"), order(h) miss
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONSEIL( DE)? STAB")
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONSEIL D'ASSOC"), order(h) miss
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONSEIL D'ASSOC")

* Code unspecified coordination meetings
*groups wpname if wpcode != "Z00" & regexm(wpname, "COORD.* UE"), order(h) miss
replace wpcode = "Z00" if regexm(wpname, "COORD.* UE")

* Code other conferences
*groups wpname if wpcode != "Z00" & regexm(wpname, "CONFERENCE") /*
	*/ & regexm(wpname, "DEVELOP") == 0, order(h) miss show(f F)
replace wpcode = "Z00" if wpcode != "Z00" & regexm(wpname, "CONFERENCE") /*
	*/ & regexm(wpname, "DEVELOP") == 0

* Code other meetings
replace wpcode = "Z00" if wpname == "REUNION TRILATERALE"
replace wpcode = "Z00" if wpname == "CSDP ORIENTATION COURSE"
replace wpcode = "Z00" if wpname == "CRIMINALITE CYBERNETIQUE"
replace wpcode = "Z00" if wpname == "PREP. CONF. TRIPARTITE CROISS. / EMPLOI"
replace wpcode = "Z00" if wpname == "RENC. COPA / COGECA"
replace wpcode = "Z00" if wpname == "CONSEIL CONJOINT UE - GOLFE"


* Check coding
tab wpcode, m
groups wpname if wpcode == "Z00", order(h) miss show(f F P)


* Identify and drop exact duplicates
duplicates report wpname date slot
duplicates list wpname date slot
duplicates tag wpname date slot, gen(dup)
sort date slot wpname_orig
list date slot wpname wpname_orig if dup > 0
* Drop all duplicates except lawyer/linguists meetings
duplicates drop wpname date slot if wpname != "JURISTES / LINGUISTES", force
* 76 observations dropped
drop dup

* Save data
sort date
order date slot year semester month week day pres wpcode*
compress
des, s
save "Data management\wpar-management04-workingparties01-clean", replace

* Exit
log close
exit

